Intro::
Spring Boot Data Redis ์ฐ๊ฒฐ ๋ฐฉ๋ฒ์ ๋ํ ์ ๋ฆฌ๋ณธ์ ๋๋ค.
ย
Config ํ์ผ ์ค์
// RedisConfig @Configuration public class RedisConfig { @Value("${spring.data.redis.host}") private String host; @Value("${spring.data.redis.password}") private String password; @Value("${spring.data.redis.port}") private int port; @Bean public RedisConnectionFactory redisConnectionFactory() { // RedisClusterConfiguration() RedisStandaloneConfiguration redisConfig = new RedisStandaloneConfiguration(); redisConfig.setHostName(host); redisConfig.setPassword(password); redisConfig.setPort(port); return new LettuceConnectionFactory(redisConfig); } @Bean public RedisTemplate<String, Object> redisTemplate() { RedisTemplate<String, Object> template = new RedisTemplate<>(); template.setConnectionFactory(redisConnectionFactory()); template.setKeySerializer(new StringRedisSerializer()); template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); return template; } }
- LettuceConnectionFactory
- RedisStandaloneConfiguration (๋จ์ผ ์ธ์คํด์ค ์ค์ )
- RedisSentinelConfiguration (Sentinel ์ค์ )
- RedisClusterConfiguration (ํด๋ฌ์คํฐ ์ค์ )
- RedisTemplate
Redis์ ๋ค์ํ ๊ธฐ๋ฅ์ ์ธ๋ฐํ๊ฒ ์ ์ดํ๊ณ , ๊ณ ๊ธ ์ฐ์ฐ ๋ฐ ๋ณต์กํ ์ฟผ๋ฆฌ๋ฅผ ์ํํด์ผ ํ ๋ ์ ํฉํฉ๋๋ค. ์ ์ฐ์ฑ๊ณผ ์ฑ๋ฅ ์ต์ ํ๊ฐ ์ค์ํ ๊ฒฝ์ฐ์ ์ ์ฉํฉ๋๋ค.
ย
๋ ๋์ค ์ ๊ทผ ๋ฐฉ๋ฒ
@Autowired RedisTemplate<String, Object> redisTemplate; ValueOperations<String, Object> ops= redisTemplate.opsForValue(); // or @Resource(name="redisTemplate") private ValueOperations<String, Object> ops; redisTemplate.hasKey(key);// ํค ํ์ธ ops.set(key, object);// ์ ์ฅ ops.get(key);// value ๊ฐ์ ธ์ค๊ธฐ
ย
Loading Comments...